﻿using NuMvvm.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuMvvm.Testing.Services
{
    public class MockNavigationService : INavigationService
    {
        private Stack<IView> _historyStack = new Stack<IView>();


        public bool CanGoBack
        {
            get
            {
                return _historyStack.Any();
            }
        }

        public bool CanGoForward
        {
            get
            {
                return false;
            }
        }

        public IView CurrentView
        {
            get;
            set;
        }

        public void GoBack()
        {
            CurrentView = _historyStack.Pop();
        }

        public void GoForward()
        {
            throw new NotSupportedException();
        }

        public void Navigate(object view)
        {
            if (CurrentView != null)
                _historyStack.Push(CurrentView);

            CurrentView = new MockView(view);
        }

        public void Navigate(object view, object arg)
        {
            if (CurrentView != null)
                _historyStack.Push(CurrentView);

            CurrentView = new MockView(view, arg);
        }
    }

    public class MockView : IView
    {
        private object arg;
        private object view;

        public MockView(object view)
        {
            this.view = view;
        }

        public MockView(object view, object arg) : this(view)
        {
            this.arg = arg;
        }

        public object Argument
        {
            get
            {
                return arg;
            }
        }

        public object View
        {
            get
            {
                return view;
            }
        }

        public object DataContext
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
